package com.newenergy.wisehome.common.helper;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.newenergy.wisehome.R;
import com.newenergy.wisehome.config.BaseApp;


/**
 * Created by dell on 2016/12/6.
 */

public class ToastUtil {

    private static Context sContext = BaseApp.getInsatance();
    private static Toast myToast;

    public static void init(Context context) {

        sContext = context;
    }

    public static void myToast(String msg) {
        myToast(msg, true);
    }

    public static void myToast(String msg, boolean isFail) {
        // 自定义土司
        Context context = sContext;
        View layout = View.inflate(context, R.layout.my_toast, null);
        TextView tvToastMsg = (TextView) layout.findViewById(R.id.tv_msg);
        tvToastMsg.setSelected(isFail);
        // 设置toast文本，把设置好的布局传进来
        tvToastMsg.setText(msg);
        if (myToast == null) myToast = new Toast(context);
        // 设置toast文本，把设置好的布局传进来
        myToast.setView(layout);
        // 设置土司显示在屏幕的位置
        myToast.setGravity(Gravity.CENTER, 0, 0);
        // 显示土司
        myToast.show();
    }

    public static void toast(String msg) {
        Toast.makeText(sContext, msg, Toast.LENGTH_SHORT).show();
    }

}
